<?php

namespace app\api\controller;

use app\common\controller\ApiBase;
use app\common\model\Dressup;

class Userdressuppackaged extends ApiBase
{
    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = [''];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    public function list()
    {
        $dressup = Dressup::alias('fd')->field('fd.*')
            ->join('fa_user_dressup_packaged fudp', 'fd.id=fudp.dressup_id', 'left')
            ->where([
                'status' => Dressup::STATUS_ON,
                function ($query) {
                    $query->whereor([
                        'fd.is_free' => Dressup::IS_FREE_YES,
                        function ($query) {
                            $query->where([
                                'fd.is_free'   => Dressup::IS_FREE_NO,
                                'fudp.user_id' => $this->auth->id
                            ]);
                        }
                    ]);
                }
            ])
            ->paginate($this->getPaginate());

        $data = $dressup->items();
        $count = $dressup->total();


        $this->success('成功', ['count' => $count, 'list' => $data]);
    }
}
